package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.LmtFreezeAppDao;
import com.fdb.efp.nls.service.domain.LmtFreezeApp;
import com.fdb.efp.nls.service.facade.LmtFreezeAppService;
import com.fdb.efp.nls.service.vo.LmtFreezeAppVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 额度冻结申请表				<p>
 *
 * @author ligm
 * @date 2019-08-10
 */
@Service("lmtFreezeAppService")
public class LmtFreezeAppServiceImpl implements LmtFreezeAppService, FrameworkService{

    private static Logger logger = LoggerFactory.getLogger(LmtFreezeAppServiceImpl.class);

    @Autowired
    private LmtFreezeAppDao lmtFreezeAppDao;

    /**
     * 新增操作
     */
    public int insertLmtFreezeApp(LmtFreezeAppVO inLmtFreezeAppVo) {
        logger.debug("当前新增数据为:" + inLmtFreezeAppVo.toString());
        int num = 0;
        try {
            LmtFreezeApp lmtFreezeApp = new LmtFreezeApp();
            beanCopy(inLmtFreezeAppVo, lmtFreezeApp);
            num = lmtFreezeAppDao.insertLmtFreezeApp(lmtFreezeApp);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 删除操作
     */
    public int deleteByPk(LmtFreezeAppVO inLmtFreezeAppVo) {
        logger.debug("当前删除数据条件为:" + inLmtFreezeAppVo);
        int num = 0;
        try {
            LmtFreezeApp lmtFreezeApp = new LmtFreezeApp();
            beanCopy(inLmtFreezeAppVo, lmtFreezeApp);
            num = lmtFreezeAppDao.deleteByPk(lmtFreezeApp);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + inLmtFreezeAppVo + "删除的数据条数为" + num);
        return num;
    }

    @Override
    public LmtFreezeAppVO queryByPk(LmtFreezeAppVO lmtFreezeAppVo) {
        logger.debug("当前查询条件条件为:" + lmtFreezeAppVo.getFrzSerno());
        try {
            LmtFreezeApp lmtFreezeApp = new LmtFreezeApp();
            beanCopy(lmtFreezeAppVo, lmtFreezeApp);
            LmtFreezeApp lmtFreeze = lmtFreezeAppDao.queryByPk(lmtFreezeApp);
            if (Objects.nonNull(lmtFreeze)) {
                LmtFreezeAppVO retuenVo = beanCopy(lmtFreeze, new LmtFreezeAppVO());
                logger.debug("当前查询结果为:" + retuenVo.toString());
                return retuenVo;
            } else {
                logger.debug("当前查询结果为空!");
            }
        }catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    /**
     * 更新操作
     */
    public int updateByPk(LmtFreezeAppVO inLmtFreezeAppVo) {
        logger.debug("当前修改数据为:" + inLmtFreezeAppVo.toString());
        int num = 0;
        try {
            LmtFreezeApp lmtFreezeApp = new LmtFreezeApp();
            beanCopy(inLmtFreezeAppVo, lmtFreezeApp);
            num = lmtFreezeAppDao.updateByPk(lmtFreezeApp);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + inLmtFreezeAppVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 查询操作
     * <p>
     * 保存前校验是否存在同一授信协议信息并未处理完成的
     */
    public List<LmtFreezeAppVO> queryLmtContNoByPk(LmtFreezeAppVO lmtFreezeAppVo) {
        logger.debug("当前查询授信协议未处理完成的参数信息为:");
        List<LmtFreezeAppVO> list = null;
        try {
            List<LmtFreezeApp> lmtFreezeApps = lmtFreezeAppDao.queryLmtContNoByPk(lmtFreezeAppVo);
            logger.debug("当前查询授信协议未处理完成的结果集数量为:" + lmtFreezeApps.size());
            pageSet(lmtFreezeApps, lmtFreezeAppVo);
            list = (List<LmtFreezeAppVO>) beansCopy(lmtFreezeApps, LmtFreezeAppVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }

        return list;
    }


    /**
     * 查询用户权限数据
     */
    @SuppressWarnings("unchecked")
    public List<LmtFreezeAppVO> queryAllOwner(LmtFreezeAppVO lmtFreezeAppVo) {

        logger.debug("当前查询本人所属数据信息的参数信息为:");
        List<LmtFreezeAppVO> list = null;
        try {
            List<LmtFreezeApp> lmtFreezeApps = lmtFreezeAppDao.queryAllOwnerByPage(lmtFreezeAppVo);
            logger.debug("当前查询本人所属数据信息的结果集数量为:" + lmtFreezeApps.size());
            pageSet(lmtFreezeApps, lmtFreezeAppVo);
            list = (List<LmtFreezeAppVO>) beansCopy(lmtFreezeApps, LmtFreezeAppVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }

        return list;

    }


    /**
     * 查询当前机构权限数据
     */
    @SuppressWarnings("unchecked")
    public List<LmtFreezeAppVO> queryAllCurrOrg(LmtFreezeAppVO lmtFreezeAppVo) {

        logger.debug("当前查询本人所属机构数据信息的参数信息为:");
        List<LmtFreezeApp> lmtFreezeApps = lmtFreezeAppDao.queryAllCurrOrgByPage(lmtFreezeAppVo);
        logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + lmtFreezeApps.size());
        List<LmtFreezeAppVO> list = null;
        try {
            pageSet(lmtFreezeApps, lmtFreezeAppVo);
            list = (List<LmtFreezeAppVO>) beansCopy(lmtFreezeApps, LmtFreezeAppVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }

        return list;

    }


    /**
     * 查询当前机构及下属机构权限数据
     */
    @SuppressWarnings("unchecked")
    public List<LmtFreezeAppVO> queryAllCurrDownOrg(LmtFreezeAppVO lmtFreezeAppVo) {

        logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
        List<LmtFreezeApp> lmtFreezeApps = lmtFreezeAppDao.queryAllCurrDownOrgByPage(lmtFreezeAppVo);
        logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + lmtFreezeApps.size());
        List<LmtFreezeAppVO> list = null;
        try {
            pageSet(lmtFreezeApps, lmtFreezeAppVo);
            list = (List<LmtFreezeAppVO>) beansCopy(lmtFreezeApps, LmtFreezeAppVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }

        return list;

    }

    @Override
    public List<LmtFreezeAppVO> queryAllByConditions(LmtFreezeAppVO lmtFreezeAppVo) {
        List<LmtFreezeAppVO> list = null;
        logger.debug("当前查询数据信息的参数信息为:"+lmtFreezeAppVo.toString());
        try {
            LmtFreezeApp lmtFreezeApp = new LmtFreezeApp();
            beanCopy(lmtFreezeAppVo, lmtFreezeApp);
            List<LmtFreezeApp> lmtFreezeApps = lmtFreezeAppDao.queryAllByConditionsByPage(lmtFreezeApp);
            logger.debug("当前查询数据信息的结果集数量为:" + lmtFreezeApps.size());
            pageSet(lmtFreezeApps, lmtFreezeApp);
            list = (List<LmtFreezeAppVO>) beansCopy(lmtFreezeApps, LmtFreezeAppVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }
        return list;
    }

    /**
     * 查询冻结流水号
     * @author xiezw
     * @params  * @param null
     * @return
     * @date 2019/11/23 11:33
     * @version 0.1
     */
    @Override
    public String queryFrzSerno(String lmtContNo){
        String frzSerno = null;
        logger.debug("当前查询数据信息的参数信息为:"+lmtContNo);
        try {
            frzSerno = lmtFreezeAppDao.queryFrzSerno(lmtContNo);
        } catch (Exception e) {
        logger.error("查询数据出现异常!", e);
        }
        return frzSerno;
    }

    @Override
    public List<LmtFreezeAppVO> queryAllCurrOwnerPrd(LmtFreezeAppVO lmtFreezeAppVo){
        List<LmtFreezeAppVO> list = null;
        logger.debug("当前查询产品种类数据信息的参数信息为:"+lmtFreezeAppVo.toString());
        try {
            LmtFreezeApp lmtFreezeApp = new LmtFreezeApp();
            beanCopy(lmtFreezeAppVo, lmtFreezeApp);
            List<LmtFreezeApp> lmtFreezeApps = lmtFreezeAppDao.queryAllCurrOwnerPrdByPage(lmtFreezeApp);
            logger.debug("当前查询产品种类数据信息的结果集数量为:" + lmtFreezeApps.size());
            pageSet(lmtFreezeApps, lmtFreezeApp);
            list = (List<LmtFreezeAppVO>) beansCopy(lmtFreezeApps, LmtFreezeAppVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }
        return list;
    }


}
